package net.dgg.zz.common.service;

import net.dgg.zz.common.dao.ProductDao;
import net.dgg.zz.common.excption.CommonExcption;
import net.dgg.zz.common.utils.ValidateUtils;
import net.dgg.zz.production.inProcess.dao.ProductOrderDao;
import net.dgg.zz.production.nodeOverdue.service.ProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.dgg.zz.common.dao.OrderDao;
import net.dgg.zz.common.entity.Order;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * 销售订单order
 *<p>@Package: net.dgg.zz.common.service</p>
 *<p>@Title：OrderService</p>
 *<p>@description:</p>
 *<p>@author liulei</p>
 *<p>@date 2018年8月31日</p>
 *<p>@Company dgg</p>
 */
@Service
public class OrderService {

	
	@Autowired
	private OrderDao orderdao;

	@Autowired
	private ProductOrderDao productOrderDao;

	@Autowired
	private ProductDao productDao;
	
	
	/**
	 * iboos插入销售订单
	 * @param order
	 * @return
	 */
	public int ibossInsert(Order order) {
		return  orderdao.iboosInsertSelective(order);
	}

	/**
	 * iboos插入销售订单
	 * @param order
	 * @return
	 */
	public int ibossInsertQdb(Order order) {
		return  orderdao.iboosInsertSelectiveQdb(order);
	}
	 /**
     * 根据销售订单Id验证重复
     * @param orderId
     * @return
     */
	public Order selectByOrderId(Long orderId) {
		return orderdao.selectByOrderId(orderId);
	}

	/**
	 * @Author sdx
	 * @Description //TODO 订单中心广播，修改合同号
	 * @Date 19:01 2019/5/13
	 * @Param
	 * @return
	 **/
	@Transactional
	public void executeUpdateContractNo(Long orderId, String contractNo) {
		ValidateUtils.strNotEmpty(orderId, CommonExcption.class, "销售订单id不能为空");
		ValidateUtils.strNotEmpty(contractNo, CommonExcption.class, "合同号不能为空");
		Map params = new HashMap();
		params.put("orderId",orderId);
		params.put("contractNo",contractNo);
		productOrderDao.updateContractNoById(params);
		orderdao.updateContractNoById(params);
		productDao.updateContractNoById(params);
	}
}
